import Vue from 'vue'
import App from './App.vue'
import router from './router/index'
import store from './store/index'

import api, {putEditStatusRequest} from './api'
Vue.prototype.$api = api

import {postRequest} from './api'
import {putRequest} from './api'
import {getRequest} from './api'
import {deleteRequest} from './api'
import {deleteDeptRequest} from './api'
import {downloadRequest} from '@/util/download'
Vue.prototype.postRequest = postRequest
Vue.prototype.putRequest = putRequest
Vue.prototype.putEditStatusRequest = putEditStatusRequest
Vue.prototype.getRequest = getRequest
Vue.prototype.deleteRequest = deleteRequest
Vue.prototype.downloadRequest = downloadRequest
Vue.prototype.deleteDeptRequest = deleteDeptRequest

// router.beforeEach((to, from, next) => { // 没有next就不会跳到下一个路由
//     if (window.localStorage.getItem('tokenStr')) {
//         initMenu(router, store)
//         next()
//     } else {
//         next()
//     }
// })

import dayjs from 'dayjs'
Vue.prototype.$dayjs = dayjs

import auth from './util/auth'
Vue.use(auth)

import cookies from 'vue-cookies'
Vue.use(cookies)

import VueMeta from 'vue-meta'
Vue.use(VueMeta)

import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
Vue.use(ElementUI)

import hotkeys from 'hotkeys-js'
Vue.prototype.$hotkeys = hotkeys

// 全局组件自动注册
import './components/autoRegister'

// 自动加载 svg 图标
const req = require.context('./assets/icons', false, /\.svg$/)
const requireAll = requireContext => requireContext.keys().map(requireContext)
requireAll(req)

import './assets/styles/reset.scss'

import './mock'

// import {initMenu} from '@/util/menus'

Vue.config.productionTip = false

Vue.prototype.$eventBus = new Vue({
    router,
    store,
    render: h => h(App)
}).$mount('#app')
